import 'package:flutter/material.dart';
import 'package:honeypotflutter/publicBussine/bussine_colors.dart';
import 'package:honeypotflutter/publicBussine/bussine_font.dart';

class HLTabBar extends StatefulWidget {
  final List<String> menuTitles;
  final TabController? controller;
  final bool isScrollable;
  final EdgeInsetsGeometry? indicatorPadding;
  final Color? backColor;
  final Function(int index)? action;
  final double radius;
  HLTabBar({
    super.key,
    required this.menuTitles,
    this.controller,
    this.isScrollable = false,
    this.indicatorPadding,
    this.backColor,
    this.action,
    this.radius = 0.0,
  }) : assert(menuTitles.isNotEmpty, "mens不能为空");

  @override
  State<HLTabBar> createState() => _HLTabBarState();
}

class _HLTabBarState extends State<HLTabBar> with SingleTickerProviderStateMixin {
  late TabController controller;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    controller = widget.controller ?? TabController(length: widget.menuTitles.length, vsync: this);
  }

  @override
  Widget build(BuildContext context) {
    return PreferredSize(
      preferredSize: const Size(0, 84),
      child: Material(
        color: widget.backColor ?? Colors.white,
        borderRadius: BorderRadius.circular(widget.radius),
        child: TabBar(
          tabs: widget.menuTitles.map((e) => Text(e)).toList(),
          isScrollable: widget.isScrollable,
          controller: controller,
          indicatorWeight: 3,
          indicatorColor: MGColors.themeColor,
          labelColor: MGColors.text1Color,
          labelStyle: const TextStyle(fontSize: MGFont.textFont1, fontWeight: FontWeight.bold),
          labelPadding: const EdgeInsets.only(bottom: 5),
          unselectedLabelColor: MGColors.text3Color,
          unselectedLabelStyle: const TextStyle(fontSize: MGFont.textFont1),
          padding: const EdgeInsets.only(top: 10, bottom: 10),
          dividerColor: Colors.transparent,
          overlayColor: MaterialStateProperty.resolveWith((states) {
            return Colors.transparent;
          }),
          onTap: (widget.action != null) ? widget.action : null,
        ),
      ),
    );
  }
}
